﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Diagnostics;

namespace NJGZBTYHXT
{
    public partial class YHJG : Form
    {
        public DataGridView dgv { get; set; }

        public YHJG()
        {
            InitializeComponent();
        }

        private void LoadData()
        {
            try
            {
                foreach (DataGridViewColumn column in dgv.Columns)
                {
                    dataGridView1.Columns.Add(column.Name, column.HeaderText);
                }

                foreach (DataGridViewRow row in dgv.Rows)
                {
                    object[] values = new object[row.Cells.Count];

                    for (int z = 0; z < row.Cells.Count; z++)
                    {
                        values[z] = row.Cells[z].Value;
                    }

                    dataGridView1.Rows.Add(values);
                }

                dataGridView1.Columns["ID"].DisplayIndex = 0;

                FirstOption.DataGridViewSHC(dataGridView1, "公示地址,开户行,帐号,分档名称,功率,结算单位,经销商,市补总额（元）,县补总额（元）,总成交价格（元）,打印日期,购机日期,申请结算日期,结算日期,申请结算批次,结算批次,发票号,出厂编号【发动机号】", false, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void YHJG_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Application.StartupPath + @"\Excel\";

                if (!Directory.Exists(path)) { Directory.CreateDirectory(path); }

                string filePath = path + DateTime.Now.ToFileTime() + ".xls";

                FirstOption.OutExcel(dataGridView1, filePath);

                if (DialogResult.OK == MessageBox.Show("生成Excel成功，文件路径为：\n" + filePath + "\n是否打开文件？", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                {
                    Process.Start(filePath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示");
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
